import { Component, OnInit, ViewChild } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

import { PagedQueryResult, PagedQueryParam, Utils, BaseComponent } from 'iisp-ng';


import { DataTable, DataTableColumn,TableDataVO } from '../dm.model.js';
import { DataManagerService } from '../dm.service.js';
import { TableDataComponent } from '../table-data/table-data.component.js';


declare var contextPath: string;

@Component({
	selector: 'tables-app',
	templateUrl: contextPath + "/templates/iisp-data-mgr/tables.tpl.ftl.htm",
	providers: [DataManagerService]
})
export class TableComponent extends BaseComponent implements OnInit {
    @ViewChild(TableDataComponent) datas: TableDataComponent;
    tables: DataTable[];
    tableDetail:TableDataVO;
    selectedTable: DataTable;
    constructor(private service: DataManagerService, private sanitizer: DomSanitizer) { super(); }

	ngOnInit(): void {
	    this.getTableList();
	}

	
	getTableList(): void {
        this.service.getTables().then(tables => {this.tables = tables}).catch(this.handleError);
    }
	
	
	selectTable(table: DataTable): void {
	    for (let u of this.tables) {
	        u.isSelected = false;
	    }
		this.selectedTable = table;
		this.selectedTable.isSelected = true;
	}
    isRunning(): boolean{
        return this.service.isRunning > 0 || this.service.isRunning > 0;
    }
	
}
